package com.adfframeworks.labs.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.adfframeworks.labs.domain.Employee;
import com.adfframeworks.labs.domain.Request;
import com.adfframeworks.labs.service.CommunityService;
import com.adfframeworks.labs.service.EmployeeService;
import com.adfframeworks.labs.service.RequestService;

@Controller
@RequestMapping(value = "/welcome/id={user_id}/request")
public class RequestController {

	@Autowired
	RequestService requestService;

	@Autowired
	EmployeeService employeeService;

	@Autowired
	CommunityService communityService;

	@RequestMapping(value = "/id={request_id}", method = RequestMethod.GET)
	public String displayRequest(@PathVariable Integer user_id, @PathVariable Integer request_id, ModelMap model) {
		System.out.println("Display the request information.");
		Request request = requestService.getRequest(request_id);
		model.addAttribute("request", request);
		model.addAttribute("from", employeeService.getEmployee(request.getFrom()));
		model.addAttribute("to", employeeService.getEmployee(request.getTo()));
		model.addAttribute("community", communityService.getCommunity(request.getCommunity()));
		return "displayRequest";
	}
}
